package com.tuotu.gps.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tuotu.gps.R;

/**
 * Created by XuYeWen on 2018/3/13.
 */

public class RecordStatusDialog extends Dialog{

    private View mLayoutStatusReady;
    private View mLayoutStatusRecording;
    private View mLayoutStatusAdd;
    private OnStatusStopListener mOnStatusStopListener;
    private int typeRecord;

    public RecordStatusDialog(@NonNull Context context) {
        super(context, R.style.SelfDialog);
    }

    public void setmOnStatusStopListener(OnStatusStopListener mOnStatusStopListener) {
        this.mOnStatusStopListener = mOnStatusStopListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_status_record);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        //点击鼠标返回键不取消动画
        setCancelable(false);
        initView();
    }

    public void setTypeRecord(int typeRecord) {
        this.typeRecord = typeRecord;
    }

    public void setViewVisibility(int i){
        mLayoutStatusReady.setVisibility(i==0?View.VISIBLE:View.GONE);
        if(typeRecord==1){
            mLayoutStatusAdd.setVisibility(i==1?View.VISIBLE:View.GONE);
            mLayoutStatusRecording.setVisibility(View.GONE);
        }else {
            mLayoutStatusAdd.setVisibility(View.GONE);
            mLayoutStatusRecording.setVisibility(i==1?View.VISIBLE:View.GONE);
        }
    }

    private void initView() {
        mLayoutStatusReady=findViewById(R.id.layout_status_ready);
        mLayoutStatusAdd=findViewById(R.id.layout_status_add);
        mLayoutStatusRecording=findViewById(R.id.layout_status_recording);
        findViewById(R.id.layout_status_stop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null!=mOnStatusStopListener)
                    mOnStatusStopListener.onStatusRecordStop();

                dismiss();
            }
        });
    }

    public interface OnStatusStopListener{
        void onStatusRecordStop();
    }
}
